<template>
  <div>
    <div>
      <el-form :inline="true" :model="POForm" class="demo-form-inline">
        <el-form-item label="订单编码" prop="poNum">
          <el-input v-model="POForm.poNum" placeholder="请输入内容" size="small"></el-input>
        </el-form-item>
        <el-form-item label="产品名称" prop="productName">
          <el-input v-model="POForm.productName" placeholder="请输入内容" size="small"></el-input>
        </el-form-item>
        <el-form-item label="供应商名称" prop="supplierName">
          <el-input v-model="POForm.supplierName" placeholder="请输入内容" size="small"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="search" size="small">搜索</el-button>
          <el-button @click="resetSearchForm('searchForm')" size="small">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <el-table v-loading="loading" :data="POList" border style="width: 100%">
      <el-table-column prop="poNum" label="采购订单编码">
      </el-table-column>
      <el-table-column prop="productName" label="产品名称">
      </el-table-column>
      <el-table-column prop="productCode" label="产品编码">
      </el-table-column>
      <el-table-column prop="supplierName" label="供应商名称">
      </el-table-column>
      <el-table-column prop="num" label="采购数量">
      </el-table-column>
      <el-table-column prop="finishFlag" label="完成状态">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.finishFlag == 1 " type="success">完成</el-tag>
          <el-tag v-else type="danger">未完成</el-tag>
        </template>
      </el-table-column>

      <el-table-column fixed="right" label="操作" width="100">
        <template slot-scope="scope">
          <el-button v-if="scope.row.finishFlag == 1" type="success" size="small">已入库</el-button>
          <el-button v-else type="danger" size="small" @click="DialogOpen(scope.row)">未入库</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage"
      :page-sizes="[5, 10, 15, 20]" :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper"
      :total="totalPage">
    </el-pagination>

    <el-dialog :visible.sync="dialogFormVisible">
      <el-form :model="form">
        <el-form-item label="采购订单编码">
          <el-input v-model="form.poNum" readonly></el-input>
        </el-form-item>
        <el-form-item label="产品名称">
          <el-input v-model="form.productName" readonly></el-input>
        </el-form-item>
        <el-form-item label="产品编码">
          <el-input v-model="form.productCode" readonly></el-input>
        </el-form-item>
        <el-form-item label="供应商名称">
          <el-input v-model="form.supplierName" readonly></el-input>
        </el-form-item>
        <el-form-item label="采购数量">
          <el-input v-model="form.num" readonly></el-input>
        </el-form-item>
        <el-form-item label="完成状态">
          <el-tag v-if="form.finishFlag == 0" type="danger">未完成</el-tag>
          <el-tag v-if="form.finishFlag == 1" type="success">已完成</el-tag>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="submitType()">入 库</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { getInRepertory, inRepertory } from '@/api/product'
export default {
  data() {
    return{
      loading: false,
      currentPage: 1,
      pageNum: 1,
      pageSize: 5,
      totalPage: 0,
      POList:[],
      dialogFormVisible:false,
      form:{
        id:0,
        poNum:'',
        productName:"",
        productCode:"",
        supplierName:"",
        num:0,
        finishFlag:0
      },
      POForm:{
        poNum:'',
        productName:"",
        supplierName:""
      }
    }
  },
  methods:{
    fetchDate(){
      this.loading = true
      getInRepertory({
        pageNum: this.pageNum,
        pageSize: this.pageSize,
        poNum:this.POForm.poNum,
        productName:this.POForm.productName,
        supplierName:this.POForm.supplierName
      }).then(res => { 
        if(res.code==200){
          this.POList = res.data.list
          this.loading = false
          this.totalPage = res.data.total
        }
})
    },
    handleSizeChange(val) {
      this.pageSize = val
      this.fetchDate()
    },
    handleCurrentChange(val) {
      this.pageNum = val
      this.fetchDate()
    },
    DialogOpen(row){
      this.form = row
      this.dialogFormVisible = true
    },
    submitType(){
      inRepertory(this.form).then(res => { 
        if(res.code==200){
          this.$message({
            message: res.msg || "入库成功",
            type: 'success'
          })
          this.dialogFormVisible = false
          this.fetchDate()
        }
})

    },
    search(){
      this.pageNum = 1
      this.fetchDate()
    },
    resetSearchForm(){
      this.POForm = {}
      this.pageNum = 1
      this.fetchDate()
    }

  },
  created() {
    this.fetchDate()
  },

}
</script>
<style scoped></style>